import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import '@/assets/js/vant.js'
import { formatDate } from '@/assets/js/common.js'
import zwList from '@/components/zw-list.vue'
import interfaces from '@/assets/js/api.js';
Vue.prototype.$api = interfaces;
import axios from 'axios';
import 'element-ui/lib/theme-chalk/index.css';
import { Select, Option, Timeline, TimelineItem, Card, Message } from 'element-ui';
Vue.use(Select)
Vue.use(Option)
Vue.use(Timeline)
Vue.use(TimelineItem)
Vue.use(Card)
Vue.prototype.$message = Message;
import { Toast } from 'vant';
// 富文本
import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme
Vue.prototype.$toast = Toast;
Vue.prototype.$hasPermiss = function hasPermiss(arr1, arr2) {
  arr1.forEach((x, index) => {
    // this[arr2[index]] = JSON.parse(window.sessionStorage.getItem('user')).permiss.find(item=>item==x)
    this[arr2[index]] = true
  })
}
// 首次可以进入home页，再次进入拦截
var homeEnterNum = 0
router.beforeEach((to, from, next) => {
  if (!homeEnterNum && to.path == '/home' || to.name == 'policyDetailReceive') {
    homeEnterNum++
    next()
  } else {
  if (!sessionStorage.getItem('token')&&to.path!='/emptyPage') return next({
    path: '/emptyPage'
  })
  if (!to.meta.permissName||to.path=='/emptyPage') {
    next()
  } else {
    if (JSON.parse(window.sessionStorage.getItem('user')).permiss.find(x=>x==to.meta.permissName)) {
    next()
    } else {
      Toast.fail("无权查看！");
    }
  }
}

})
// router.afterEach((to,from)=>{
//     // if (from.name=='questionBank'&&to.name == 'questionDetail') {
//     //   from.meta.keepAlive = true;
//     // } else {
//     //   from.meta.keepAlive = false;
//     // }
//     if (from.name=='home'&&to.name == 'questionBank') {
//       window.location.reload()
//     }
//     console.log('from.meta.keepAlive',from.meta.keepAlive);
    
// })

Vue.component('zwList', zwList)
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
